package com.swt.testdemo.controller;

import com.swt.testdemo.config.ResponseBean;
import com.swt.testdemo.config.ResponseMessage;
import com.swt.testdemo.form.CreateMsgForm;
import com.swt.testdemo.form.EditMsgForm;
import com.swt.testdemo.form.QueryMsgForm;
import com.swt.testdemo.service.SysMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020/11/11 17:01
 **/
@RestController
@RequestMapping(value = "/sys/msg")
@Api(tags = "后台管理--消息管理")
@Slf4j

public class SysMsgController {

     @Autowired
     private SysMsgService sysMsgService;

     @ApiOperation("01 查看消息列表")
     @GetMapping(value = "/list")
     public ResponseEntity<ResponseBean> listMsg(QueryMsgForm form){
          ResponseBean response = sysMsgService.listMsg(form);
          return ResponseEntity.status(response.getStatus()).body(response);

     }

     @ApiOperation("02 查看单个消息")
     @GetMapping(value = "/info")
     @ApiImplicitParam(name = "msgId",value = "消息id",paramType = "query",dataType = "int",defaultValue = "1")
     public ResponseEntity<ResponseBean> getMsgInfo(Integer msgId){
          ResponseBean response = sysMsgService.getMsgInfo(msgId);
          return ResponseEntity.status(response.getStatus()).body(response);

     }

     @ApiOperation("03 创建消息")
     @PostMapping("/create")
     public ResponseEntity<ResponseBean> createMsg(CreateMsgForm form){
          ResponseBean response = sysMsgService.createMsg(form);
          return ResponseEntity.status(response.getStatus()).body(response);

     }

     @ApiOperation("04 编辑消息")
     @PutMapping("/edit")
     public ResponseEntity<ResponseMessage> editMsg(EditMsgForm form){
          ResponseMessage response = sysMsgService.editMsg(form);
          return ResponseEntity.status(response.getStatus()).body(response);
     }

     @ApiOperation("05 删除消息")
     @DeleteMapping("/delete")
     @ApiImplicitParam(name = "msgId",value = "消息id",paramType = "query",dataType = "int",defaultValue = "100")
     public ResponseEntity<ResponseMessage> delMsg(Integer msgId){
          ResponseMessage response = sysMsgService.delMsg(msgId);
          return ResponseEntity.status(response.getStatus()).body(response);

     }
}
